<template>
  <information />

  <div class="btn-use" @click="showToast" style="margin-top: 73px">
    使用设备
  </div>
  <div class="btn-err" @click="jump">提报故障</div>
</template>
<script setup>
import { basicData } from "../store/data.js";
import information from "../components/information.vue";
import { getCurrentInstance, ref, onBeforeMount } from "vue";
import { useRouter, useRoute } from "vue-router";
const { proxy } = getCurrentInstance();
const store = basicData();
let is_show = ref(false); //弹框的显示隐藏
const router = useRouter();
const route = useRoute();
//扫码进入页面 获取设备id
onBeforeMount(() => {
  /*   console.log(route.query.id, 199); */
  proxy.$axios
    .post(`${proxy.baseUrl}/phase/getEquipment`, { id: route.query.id })
    .then((res) => {
      if (res.data.code == 0) {
        alert(res.data.msg);
      } else {
        store.$patch((state) => {
          state.basicData = res.data.data;
          state.department_name = res.data.data.department.name;
        });
      }
    })
    .catch((res) => {
      console.log(res, 1998);
      // message({ text: "服务器错误" });
    });
});
//提报故障
const jump = () => {
  router.push({
    path: "/home",
    /* query: {
      id: 1,
    }, */
  });
};
// 使用设备
const showToast = () => {
  if (store.basicData.status == 2) {
    alert("该设备已经被停用");
    return false;
  }
  proxy.$axios
    .post(`${proxy.baseUrl}/phase/employ`, {
      equipment_id: store.basicData.id,
    })
    .then((res) => {
      // message({ text: res.data.msg });
      alert(res.data.msg);
    })
    .catch((res) => {
      console.log(res);
    });
};

//关闭弹框
const stop = () => {
  is_show.value = false;
  document.body.style.overflow = "";
};
</script>
<style scoped>
</style>